package com.usian.article.controller;

import com.usian.api.article.ApArticleControllerApi;
import com.usian.article.service.ApArticleService;
import com.usian.model.article.dto.ArticleHomeDto;
import com.usian.model.article.dto.ArticleDto;
import com.usian.model.article.dto.ArticleInfoDto;
import com.usian.model.article.pojos.ApArticle;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleControllerApi {

    @Autowired
    private ApArticleService articleService;

    @Override
    @PostMapping("/save")
    public ApArticle saveApArticle(@RequestBody ApArticle apArticle) {
        return articleService.saveApArticle(apArticle);
    }

    /**
     * app 文章查询列表  默认
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)1,dto);
    }

    /**
     * app 文章查询列表  上拉加载更多
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)1,dto);
    }

    /**
     * app 文章查询列表  下拉刷新
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)2,dto);
    }

    @Override
    @PostMapping("/load_article_info")
    public ResponseResult loadArticleInfo(@RequestBody ArticleDto dto) {
        return articleService.loadArticleInfo(dto);
    }

    @Override
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto) {
        return articleService.loadArticleBehavior(dto);
    }

    /**
     * 获取发布后的文章
     *
     * @return
     */
    @Override
    @PostMapping("/findArticleList")
    public List<ApArticle> findArticleList() {
        return articleService.list();
    }
}
